<%@ include file="/common/taglibs.jsp"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<head>
	<title><fmt:message key="buyGiftCertificate.title"/></title>
</head>

<content tag="position">
	<fmt:message key="accountMenu.coupon"/> &gt; <b> <fmt:message key="helpCenter.quickLink.buyGiftCertificate"/></b>
</content>

<spring:bind path="shoppingcartItemGc.*">
	<c:if test="${not empty status.errorMessages}">
		<div class="msg-clew">
			<c:forEach var="error" items="${status.errorMessages}">
				<c:out value="${error}" escapeXml="false" />
				<br />
			</c:forEach>
		</div>
	</c:if>
</spring:bind>

<%
	String url = request.getAttribute("preUrl").toString();
	request.setAttribute("noCustomer", url.indexOf("customer")==-1);
 %>
<div <c:if test="${noCustomer}">class="wrap_11"</c:if> >
	<div <c:if test="${noCustomer}">class="wrap_05"</c:if> >
		<div class="coupon_filter">
			<p>
				<b><fmt:message key="giftCertificateBuy.description"/>：</b><br />
				<fmt:message key="giftCertificateBuy.note1"/><br />
				<fmt:message key="giftCertificateBuy.note2"/><br />
				<fmt:message key="giftCertificateBuy.note3"/>
			</p>
			<ins></ins>
		</div>
		<div class="present_coupons">
		<form:form method="post" action="${ctxPath}/buyGiftCertificate.html?doAction=saveAndCheckout" onsubmit="return validateShoppingcartItemGc(this);" id="shoppingcartItemGc"  commandName="shoppingcartItemGc">
			<input type="hidden" name="shoppingcartItemGcId" value="${shoppingcartItemGc.shoppingcartItemGcId}" />
			<table width="100%" border="0" cellspacing="0" cellpadding="0" class="present_coupons_table">
				<tr>
					<th style="width:120px;"><eStore:label key="giftCertificate.giftCertAmt" /></th>
					<td>
						(<common:currencyFormat value="${appConfig.giftCertificateMinAmt}" /> - 
						<common:currencyFormat value="${appConfig.giftCertificateMaxAmt}" />)<br/><br/>
						<spring:bind path="shoppingcartItemGc.giftCertAmt">
							<c:choose>
								<c:when test="${(not empty status.value) and (status.value!=0)}">
									<c:set var="giftCertAmt" value="${status.value}" />
								</c:when>
								<c:otherwise>
									<c:set var="giftCertAmt" value="${appConfig.giftCertificateMinAmt}" />
								</c:otherwise>
							</c:choose>
							<span><input type="text" class="inputtxt2" style="width:150px"
								name="<c:out value="${status.expression}"/>"
								id="<c:out value="${status.expression}"/>"
								value="${giftCertAmt}" /></span>
							<span class="fieldError"><c:out value="${status.errorMessage}" /> </span>
						</spring:bind> 
					</td>
				</tr>
				<tr>
					<th><eStore:label key="giftCertificate.recipientEmail" /></th>
					<td>
						<spring:bind path="shoppingcartItemGc.recipientEmail">
							<input type="text" class="inputtxt2" style="width:150px"
								name="<c:out value="${status.expression}"/>" size="45"
								id="<c:out value="${status.expression}"/>"
								value="<c:out value="${status.value}"/>" />
							<span class="fieldError"><c:out value="${status.errorMessage}" /> </span>
						</spring:bind>
					</td>
				</tr>
				<tr>
					<th><eStore:label key="giftCertificate.recipient" /></th>
					<td>
						<spring:bind path="shoppingcartItemGc.recipient">
							<input type="text" class="inputtxt2" style="width:150px"
								name="<c:out value="${status.expression}"/>"
								id="<c:out value="${status.expression}"/>"
								value="<c:out value="${status.value}"/>" />
							<span class="fieldError"><c:out value="${status.errorMessage}" /> </span>
						</spring:bind>
					</td>
				</tr>
				<tr>
					<th><eStore:label key="giftCertificate.purchaser" /></th>
					<td>
						<spring:bind path="shoppingcartItemGc.purchaser">
							<input type="text" class="inputtxt2" style="width:150px"
								name="<c:out value="${status.expression}"/>"
								id="<c:out value="${status.expression}"/>"
								value="<c:out value="${status.value}"/>" />
							<span class="fieldError"><c:out value="${status.errorMessage}" /> </span>
						</spring:bind>
					</td>
				</tr>
				<tr>
					<th><eStore:label key="giftCertificate.message" /></th>
					<td>
						<spring:bind path="shoppingcartItemGc.message">
							<textarea name="${status.expression}" class="textareatxt2" style="width:250px"
								id="${status.expression}" cols=""  rows="6">${status.value}</textarea>
							<span class="fieldError"><c:out value="${status.errorMessage}" /> </span>
						</spring:bind>
					</td>
				</tr>
				<tr>
					<td></td>
					<td>
						<div id="submitDiv">
							<input type="button" class="submit" onclick="return buyGift();">
						</div>
					</td>
				</tr>
			</table>
		</form:form>
		</div>
	</div>
</div>		
			
<c:set var="probizJs_validation" value="true" scope="request"/>
<v:javascript formName="shoppingcartItemGc" staticJavascript="false"></v:javascript>
<script type="text/javascript">
$j(document).ready(function () {
	applyValidate($("giftCertAmt"),"required,minValue=${appConfig.giftCertificateMinAmt},maxValue=${appConfig.giftCertificateMaxAmt},integer");
});

function buyGift() {
	var frmNode = $j('#shoppingcartItemGc')[0];
	if (validateShoppingcartItemGc(frmNode)) {
		$j("#submitDiv").html("<i class='loading'><fmt:message key="common.loading"/></i>");
		frmNode.submit();
		return true;
	} else {
		return false;
	}
}
</script>
